// pages/online/online.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    token: "",
    show: false,
    Information: [],
    Information1: [],
    columns: [],
    phone: "",
    phone1: "",
    phone2: "",
    phone3: "",
    name: "请选择",
    abouced: []
  },
  field() {
    wx.switchTab({
      url: '../noutonp/noutonp'
    })
  },
  onChange(event) {
    this.setData({
      phone1: event.detail
    })
  },
  onChange1(event) {
    this.setData({
      phone2: event.detail
    })
  },
  showPopup() {
    this.setData({
      show: true
    });
  },

  onClose() {
    this.setData({
      show: false
    });
  },
  onChange2(event) {
  //console.log(event.detail);
    this.setData({
      phone4: event.detail.value
    })

  },
  button() {
    var _this = this
  //console.log(this.data.Information);
  //console.log(
      _this.data.Information.name,
      _this.data.Information.mobilePhone,
      _this.data.Information.idNumber,
      _this.data.Information1.corpName,
      _this.data.Information1.pid,
      _this.data.Information.deptId,
      _this.data.Information.enterpriseName,

    wx.request({
      url: `https://fintech-wx.szjrgzjg.com//api/authorize/apply`,
      data: {
        name: _this.data.Information.name,
        phone: _this.data.Information.mobilePhone,
        idNumber: _this.data.Information.idNumber,
        corpName: _this.data.Information1.corpName,
        branchCode: _this.data.Information1.corpKey,
        subBranchCode: _this.data.Information.deptId,
        subBranchName: _this.data.Information.enterpriseName,
      },
      header: {
        'content-type': 'application/json',
        "TOKEN": _this.data.token
      },
      method: "post",
      success: function (data) {
      //console.log("+++++", data.data);
        if ( data.data.msg=="申请提交成功!") {
          wx.switchTab({
            url: '../succeed/succeed'
          })
        }else{
          wx.switchTab({
            url: '../fail/fail'
          })
        }


      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var _this = this
    var Information = wx.getStorageSync('Information')
    var abouced = wx.getStorageSync('abouced')
    var token = wx.getStorageSync('token')
  //console.log(Information);
  //console.log(abouced);
    this.setData({
      Information: Information,
      phone: Information.enterpriseName,
      Information1: abouced,
      token: token,
      phone3: abouced.corpName
    })

    if (abouced !== "") {
      wx.request({
        url: `https://fintech-wx.szjrgzjg.com//api/authorize/query/sub-branch/list`,
        data: {
          corpKey: abouced.corpKey
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          "TOKEN": _this.data.token
        },
        method: "post",
        success: function (data) {
        //console.log("+++++", data.data.data);
          var a = []
          data.data.data.forEach((i, l) => {
            a.push(i.corpName)
          })
        //console.log(a);
          _this.setData({
            columns: a
          })
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})